package com.mantru.iotpot.setting.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.mantru.iotpot.DateClass.ErrorData;
import com.mantru.iotpot.DateClass.Set_Seasoning_Calibration_Date;
import com.mantru.iotpot.R;

import java.util.List;

public class FaultLogAdapter extends RecyclerView.Adapter<FaultLogAdapter.ViewHolder>{
    private List<ErrorData> list;
    @NonNull
    @Override
    public FaultLogAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_fault_log, parent, false);
        return new FaultLogAdapter.ViewHolder(view);
    }

    public FaultLogAdapter(List<ErrorData> dates) {
        this.list = dates;
    }

    @Override
    public void onBindViewHolder(@NonNull FaultLogAdapter.ViewHolder holder, int position) {
        ErrorData errorData = list.get(position);
        holder.code.setText(errorData.getErrorCode());
        holder.desc.setText(errorData.getErrorDesc());
        holder.type.setText(errorData.getErrorType());
        holder.time.setText(errorData.getErrorTime());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{

        private final TextView code;
        private final TextView type;
        private final TextView desc;
        private final TextView time;

        public ViewHolder(View view){
            super(view);
            code = view.findViewById(R.id.adapter_fault_log_code);
            type = view.findViewById(R.id.adapter_fault_log_type);
            desc = view.findViewById(R.id.adapter_fault_log_desc);
            time = view.findViewById(R.id.adapter_fault_log_time);
        }
    }

    // 添加setData方法
    public void setData(List<ErrorData> newData) {
        list = newData;
        notifyDataSetChanged(); // 通知数据发生改变
    }
}
